<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>系统登录</title>
<link rel="shortcut icon" href="static/image/logo01.ico"/>
<link href="static/easyui/themes/default/easyui.css" rel="stylesheet">
<link href="static/easyui/themes/icon.css" rel="stylesheet"
	type="text/css" />
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
</head>
<body>
	<div style="margin: 20px 0;"></div>
	<div class="easyui-panel" title="登录" style="width: 400px">
		<div style="padding: 10px 60px 20px 60px">
			<form id="loginForm">
				<table>
					<tr>
						<td>账号：</td>
						<td><input class="easyui-textbox" type="text" id="username"
							name="username"></input></td>
					</tr>
					<tr>
						<td>密码：</td>
						<td><input class="easyui-passwordbox" type="password"
							id="password" name="password"></input></td>
					</tr>
				</table>
			</form>
			<div style="text-align: center; padding: 5px">
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">登录</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">重置</a>
				<a href="javascript:void(0)" class="easyui-linkbutton" onclick="toRegister()">注册</a>
				<a href="javascript:void(0)" onclick="openWindow()">忘记密码</a>
			</div>
		</div>
	</div>
	<div id="win" class="easyui-window" title="My Window" style="width:600px;height:400px;" data-options="iconCls:'icon-save',modal:true,closed:true">
		<table >
			<tr>
				<td>账号：</td>
				<td>
					<input class="easyui-textbox" type="text" id="username2" name="username2"></input>
				</td>
			</tr>
			<tr>
				<td>邮箱：</td>
				<td>
					<input class="easyui-textbox" type="text" id="emailAddress" name="emailAddress"></input>
				</td>
			</tr>
		</table>
		<div style="padding: 5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="sendEmail()">发送</a>
		</div>
	    
	</div>
	<script>
		// 点击登录
		function submitForm() {
			var username = $("#username").val();
			var password = $("#password").val();
			$.ajax({
				type : "post",
				url : "login",
				data : {
					username : username,
					password : password
				},
				success : function(data) {
					if (data.code == 0) {
						$.messager.alert('提示信息',data.message,"info", function() {
							if(username == 'admin') {
								document.location.href="manage/admin/admin.jsp"
							} else {							
								document.location.href="manage/index.jsp"
							}
						});
						
					} else {
						$.messager.alert({
							title : '提示信息',
							msg : data.message,
							icon : "error"
						});
					}
					
				}
			});

		}
		// 点击重置, 清空
		function clearForm() {
			$('#loginForm').form('clear');
		}
		// 点击注册, 跳转到注册页面
		function toRegister() {
			window.location.href = "register.jsp";
		}
		
		function openWindow() {
			$("#win").window('open');
		}
		// 向客户的邮箱发送邮件
		function sendEmail() {
			var username = $("#username2").val();
			var emailAddress = $("#emailAddress").val();
			console.log(username, emailAddress);
			$.ajax({
				url:"checkEmail",
				type: "post",
				data:{
					username: username,
					emailAddress: emailAddress
				},
				success: function(response) {
					if(response.code = 0) {
						$.messager.alert('提示信息', response.message +",请前往邮箱查看", "info");
					} else {
						$.messager.alert( '提示信息', response.message, "info");
					}
				}
			})
		}
	</script>
</body>
</html>